package com.cljh.service.impl;

import com.cljh.bean.Article;
import com.cljh.controller.page.PageBean;
import com.cljh.controller.page.ProductPageBean;
import com.cljh.mapper.ArticleMapper;
import com.cljh.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
@Service
public class ArticleServiceImpl implements ArticleService {
    @Autowired
    ArticleMapper articleMapper;
    @Override
    public PageBean<Article> selectAllByCondition(Integer currentPage, Integer pageSize, Article article) {
        //计算开始索引
        int begin = (currentPage - 1) * pageSize;

        Date createTime = article.getCreateTime();


        String title = article.getTitle();
        if (title != null && title.length() > 0) {
            article.setTitle("%" + title + "%");
        }

        List<Article> articles = articleMapper.selectAllByCondition(begin, pageSize, article);
        int i = articleMapper.selectByCount(article);
        PageBean<Article> pageBean = new PageBean<>();
        pageBean.setRows(articles);
        pageBean.setTotalCount(i);
        return pageBean;
    }

    @Override
    public boolean save(Article article) {
        return articleMapper.save(article)>0;
    }

    @Override
    public boolean update(Article article) {
        return articleMapper.update(article)>0;
    }

    @Override
    public boolean deleteByIds(List<Integer> ids) {
        return articleMapper.deleteByIds(ids)>0;
    }

    @Override
    public Article selectById(Integer id) {
        return articleMapper.selectById(id);
    }

    @Override
    public boolean deleteById(Integer id) {
        return articleMapper.deleteById(id)>0;
    }

    @Override
    public List<Article> ArticleList() {
        return articleMapper.ArticleList();
    }

    @Override
    public List<Article> selectByAdmin(Integer id) {
        return articleMapper.selectByAdmin(id);
    }
}
